package com.hashkey.wxbasemodule.base;

import android.app.Activity;
import android.app.Application;
import android.content.pm.ApplicationInfo;
import android.os.Bundle;

import com.hashkey.wxbasemodule.IPageRouter;
import com.hashkey.wxbasemodule.manager.ResumedActivityManager;

/**
 * Created by louyaming on 2020/4/21.
 */
public abstract class BaseApplication extends Application {
    private static BaseApplication baseApplication;

    @Override
    public void onCreate() {
        super.onCreate();

        baseApplication = this;

//        FlutterBoostInit.init(this,isDebug(),getPageRoute());
    }

    protected abstract IPageRouter getPageRoute();

    private void setCurrentActivity(){
        registerActivityLifecycleCallbacks(new ActivityLifecycleCallbacks() {
            @Override
            public void onActivityCreated(Activity activity, Bundle savedInstanceState) {

            }

            @Override
            public void onActivityStarted(Activity activity) {

            }

            @Override
            public void onActivityResumed(Activity activity) {
                ResumedActivityManager.getInstance().setCurrentActivityWeakRef(activity);
            }

            @Override
            public void onActivityPaused(Activity activity) {

            }

            @Override
            public void onActivityStopped(Activity activity) {

            }

            @Override
            public void onActivitySaveInstanceState(Activity activity, Bundle outState) {

            }

            @Override
            public void onActivityDestroyed(Activity activity) {

            }
        });
    }

    public boolean isDebug() {
        try {
            ApplicationInfo info = getApplicationInfo();
            return (info.flags & ApplicationInfo.FLAG_DEBUGGABLE) != 0;
        } catch (Exception e) {
            e.printStackTrace();
        }

        return false;
    }

    public static BaseApplication getAppContext() {
        return baseApplication;
    }
}
